package net.maku.controller;


import org.springdoc.core.annotations.ParameterObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RequestPart;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.validation.Valid;
import lombok.AllArgsConstructor;
import net.maku.aop.Session;
import net.maku.bean.param.LoginUserParam;
import net.maku.bean.query.WebPayRecordQuery;
import net.maku.bean.query.WebTradeRecordQuery;
import net.maku.bean.vo.WebPayRecordVO;
import net.maku.bean.vo.WebTradeRecordVO;
import net.maku.bean.vo.WebUserVO;
import net.maku.entity.WebUserEntity;
import net.maku.service.WebUserService;
import net.maku.service.impl.LoginInfoServiceImpl;
import net.maku.service.impl.WebPayRecordServiceImpl;
import net.maku.service.impl.WebTradeRecordServiceImpl;
import net.maku.utils.PageResult;
import net.maku.utils.Result;

@RestController
@Tag(name="用户登录处理")
@AllArgsConstructor
public class LoginInfoController {
    
    //@Session
    @RequestMapping("/login")
    @Operation(summary = "用户登录")
    //public Result<PageResult<WebUserVO>> login( @RequestBody String str ){
    //public Result<PageResult<WebUserVO>> login(@ParameterObject @Valid LoginUserParam query){
    public Result<String> login( @RequestBody @Valid LoginUserParam query){
    	System.out.println( query.toString() );
    	System.out.println( "0000000000000000000000000000000000000000000000" );
    	/*
    	if( StringUtils.isNotBlank(query.getOpenid()) && StringUtils.isNotBlank(query.getWeixinnmb()) ){
    		return Result.ok();
    	}else {
    		return Result.error("处理失败");
    	}*/
    	return Result.ok( loginInfoServiceImpl.userLogin( query ));
    	
    }
    
    @Session
    @RequestMapping("/getuserinfo")
    @Operation(summary = "用户登录")
    public Result<WebUserEntity> getuserinfo(@RequestBody @Valid LoginUserParam query){
    	WebUserEntity bean = loginInfoServiceImpl.getUserInfo(query);
    	System.out.println( "====================================" );
    	System.out.println( query.toString() );
    	System.out.println( bean.toString() );
    	return Result.ok(bean);
    }
    
    
    @RequestMapping(value = "/uploadphoto", headers = "content-type=multipart/form-data")
    @Operation( summary = "打印文件上传" )
	public Result<String>  fileUpload( HttpServletRequest  req, 
			@RequestParam(value = "userid" ) String userid,
			@RequestPart("file") MultipartFile upfile ) {
		
		System.out.println( upfile.getSize() );
		System.out.println( upfile.getOriginalFilename() );
		System.out.println( userid );

		return Result.ok("测试成功了");
	}


    @RequestMapping("/payamount")
    @Operation(summary = "用户登录")
    //public Result<PageResult<WebUserVO>> login( @RequestBody String str ){
    //public Result<String> payamount( @RequestBody @Valid LoginUserParam query){
    public Result<String> payamount(@ParameterObject @Valid WebPayRecordQuery query){
    	loginInfoServiceImpl.saveTrade(query);
    	System.out.println( query.toString() );
    	return Result.ok("处理成功");
        
    }
    
    @Autowired
    LoginInfoServiceImpl loginInfoServiceImpl;
}


